<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <button id="btn">请求数据</button>
  <ul id="ul"></ul>

  <script>
    let btn = document.getElementById('btn')
    let ul = document.getElementById('ul')

    // ajax
    function getData(url) {
      return new Promise((resolve) => {
        let xhr = new XMLHttpRequest();
        xhr.open('GET', url, true)
        xhr.send();
        xhr.onreadystatechange = function () {
          if (xhr.readyState === 4 && xhr.status === 200) {
            resolve(xhr.responseText)
          }
        }
      })

    }

    function renderLi(arr) {
      arr.forEach(item => {
        let li = document.createElement('li');
        li.innerText = item.nm
        ul.appendChild(li);
      });
    }

    btn.addEventListener("click", () => {
      // getData('https://mock.mengxuegu.com/mock/65a91543c4cd67421b34c898/movie/movieList')
      // .then((res) => {
      //   console.log(JSON.parse(res));
      //   renderLi(JSON.parse(res).movieList)
      // })

      fetch('https://mock.mengxuegu.com/mock/65a91543c4cd67421b34c898/movie/movieList')
      .then(data => {
        return data.json()
      })
      .then(res => {
        console.log(res);
      })

    })
  
  
    // btn2.addEventListener("click", () => {
    //   getData('xxxxx').then()
    // })



  </script>

</body>

</html>